Public Class FrmAccount
    Dim cdata As Data
    Public vAddNew As Boolean = False
    Dim DoCrypt As Encrypt
    Public Acct_ID As Integer
    Private Sub SetConnectionString()
        Try
            Dim cdata As New Data
            cdata.GetConfigData()
            If cdata.UseTrust = True Then
                My.MySettings.Default("db_VirtualDeskConnectionString") = cdata.TrustConnStr
            Else
                My.MySettings.Default("db_VirtualDeskConnectionString") = cdata.ConnStr
            End If

            My.MySettings.Default.Save()


        Catch ex As Exception
            MessageBox.Show(ex.ToString, "Virtual Desk", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Err.Clear()

        End Try
    End Sub
    Function ConfigureScreen() As Boolean
        SetConnectionString()
        cdata = New Data
        cdata.BindingDropDown(Me.cbophycity, "CITY", "CITY", "SELECT DISTINCT CITY FROM TBL_ZIPCODES")
        cdata.BindingDropDown(Me.cbocity, "CITY", "CITY", "SELECT DISTINCT CITY FROM TBL_ZIPCODES")
        If TBL_ACCOUNTTableAdapter.GetData.Rows.Count > 0 Then
            Acct_ID = Me.TBL_ACCOUNTTableAdapter.GetData().Rows(0).Item(0)
            vAddNew = False
            Me.TBL_ACCOUNTTableAdapter.FillByACCT_ID(Me.DsTempList.TBL_ACCOUNT, Acct_ID)
        Else
            Me.TBL_ACCOUNTTableAdapter.FillByACCT_ID(Me.DsTempList.TBL_ACCOUNT, Acct_ID)
        End If
        Me.DsTempList.AcceptChanges()

        If vAddNew = True Then
            Me.TBLACCOUNTBindingSource.AllowNew = True
            Me.TBLACCOUNTBindingSource.AddNew()
        Else
            Me.DialogResult = Windows.Forms.DialogResult.OK
            'Me.Close()
        End If
    End Function

    Private Sub txtPassword_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPassword.GotFocus
        If Me.txtPassword.Text.Trim <> "" Then
            DoCrypt = New Encrypt
            Me.txtPassword.Text = DoCrypt.decryption(Me.txtPassword.Text.Trim)
        End If
    End Sub

    Private Sub txtPassword_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtPassword.LostFocus
        If Me.txtPassword.Text.Trim <> "" Then
            DoCrypt = New Encrypt
            Me.txtPassword.Text = DoCrypt.encryption(Me.txtPassword.Text.Trim)
        End If
    End Sub
    Private Sub txtPassword_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPassword.TextChanged

    End Sub

    Private Sub FrmAccount_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ConfigureScreen()
    End Sub

    Private Sub cbocity_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbocity.SelectedIndexChanged
        cdata.BindingDropDown(Me.cboZipcode, "ZIPCODE", "ZIPCODE", "SELECT CITY,ZIPCODE FROM TBL_ZIPCODES WHERE CITY LIKE '%" & Me.cbocity.Text & "%'")

    End Sub

    Private Sub cbophycity_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbophycity.SelectedIndexChanged
        cdata.BindingDropDown(Me.cbophyzipcode, "ZIPCODE", "ZIPCODE", "SELECT CITY,ZIPCODE FROM TBL_ZIPCODES WHERE CITY LIKE '%" & Me.cbophycity.Text & "%'")
    End Sub

    Private Sub btn_Close_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Close()
    End Sub

    Private Sub btn_save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_save.Click
        Try
            If txtVerifyPass.Text <> Me.txtPassword.Text Then
                MessageBox.Show("Password and Verify Password Not Match", "Virtual Desk", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Exit Sub
            End If
            Me.TBLACCOUNTBindingSource.EndEdit()
            ''DsTempList.TBL_ACCOUNT.Merge(DsTempList.TBL_ACCOUNT)
            Me.TBL_ACCOUNTTableAdapter.Update(DsTempList.TBL_ACCOUNT)
            MessageBox.Show("User Information Sucessfully Updated", "Virtual Desk", MessageBoxButtons.OK, MessageBoxIcon.Information)
            If vAddNew = True Then
                If Me.TBL_ACCOUNTTableAdapter.GetDataByACCT_ID(1).Rows.Count > 0 Then
                    Me.DialogResult = Windows.Forms.DialogResult.OK
                    Me.Close()
                Else
                    Me.DialogResult = Windows.Forms.DialogResult.No
                    Me.Close()
                End If
            Else
                Me.Close()
            End If
        Catch ex As Exception
            MessageBox.Show(ex.ToString, "Virtual Desk", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Err.Clear()
        End Try
    End Sub

    Private Sub btn_Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Cancel.Click
        Me.Close()
    End Sub

 
    Private Sub lnkUsePostalAdd_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lnkUsePostalAdd.LinkClicked
        Me.txtphyadd1.Text = Me.txtAdd1.Text
        Me.txtphyadd2.Text = Me.txtAdd2.Text
        Me.txtphyadd3.Text = Me.txtAdd3.Text
        Me.cbophycity.SelectedValue = Me.cbocity.SelectedValue
        cdata.BindingDropDown(Me.cbophyzipcode, "ZIPCODE", "ZIPCODE", "SELECT CITY,ZIPCODE FROM TBL_ZIPCODES WHERE CITY LIKE '%" & Me.cbophycity.Text & "%'")
        Me.cbophyzipcode.SelectedValue = Me.cboZipcode.SelectedValue
        Me.txtphystate.Text = Me.txtState.Text
    End Sub

    Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click

    End Sub

    Private Sub txtVerifyPass_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtVerifyPass.GotFocus
        If Me.txtVerifyPass.Text.Trim <> "" Then
            DoCrypt = New Encrypt
            Me.txtVerifyPass.Text = DoCrypt.decryption(Me.txtVerifyPass.Text.Trim)
        End If
    End Sub

    Private Sub txtVerifyPass_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtVerifyPass.LostFocus
        If Me.txtVerifyPass.Text.Trim <> "" Then
            DoCrypt = New Encrypt
            Me.txtVerifyPass.Text = DoCrypt.encryption(Me.txtVerifyPass.Text.Trim)
        End If
    End Sub
End Class